package hotLeetcode;

public class H45Leetcode {
    public static int jump1(int[] nums) {

        int end = 0;
        int steps = 0;
        int max = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            max = Math.max(max, nums[i] + i);
            if (i == end) {
                end = max;
                steps++;
            }

        }

        return steps;

    }

    public  static int jump(int[] nums) {
        int  end = 0;
        int jumps = 0;
        int farthest = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            farthest = Math.max(farthest, nums[i] + i);
            if (i == end) {
                end = farthest;
                jumps++;
            }
        }

        return jumps;
    }




    public static void main(String[] args) {
        int[] nums = {2, 3, 1, 1, 4};
        System.out.println(H45Leetcode.jump(nums));
    }
}
